/* eslint-disable */
// const CracoAntDesignPlugin = require('craco-antd');
const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');

const CracoLessPlugin = require('craco-less')
const path = require('path');
const { ReactInspectorPlugin } = require("react-dev-inspector/plugins/webpack");
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
// const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const WebpackBar = require("webpackbar");
const { whenDev, whenProd } = require("@craco/craco");
module.exports = {
	webpack: {
		alias: {
			'@src': path.resolve('src'),
			'@apis': path.resolve('src/apis'),
			'@components': path.resolve('src/components'),
			'@pages': path.resolve('src/pages'),
			"@images": path.resolve("src/static/images"),
			"@static": path.resolve("src/static")
		},
		plugins: [
			new AntdDayjsWebpackPlugin(),

			// webpack构建进度条
			new WebpackBar({
				profile: true,
			}),
			//查看包的大小
			// ...whenDev(() => [new BundleAnalyzerPlugin()], []),
			// 打压缩包
			...whenProd(
				() => [
					new CompressionWebpackPlugin({
						filename: "[path].gz[query]",
						algorithm: "gzip",
						test: new RegExp(
							"\\.(" + ["js", "css", "ts", "tsx"].join("|") + ")$"
						),
						threshold: 1024,
						minRatio: 0.8,
						deleteOriginalAssets: false, //删除原文件
					}),
				],
				[]
			),
			//去除生产console
			...whenProd(
				() => [
					new TerserPlugin({
						terserOptions: {
							compress: {
								// drop_console: isPro, //移除console 注意会移除所有的console.*
								drop_debugger: true, //移除debugger
								pure_funcs: ["console.log"], // 移除console.log函数
							},
						},
					}),
				],
				[]
			),
		],
	},
	plugins: [
		{
			plugin: CracoLessPlugin,
			options: {
				lessLoaderOptions: {
					lessOptions: {
						// 修改主题色 
						javascriptEnabled: true,
						modifyVars: {
							"@font-size-base": "12px",
							"@border-radius-base": "2px",
						},
					},
				},
			},
		},
		// {
		// 	plugin: CracoAntDesignPlugin,
		// 	options: {
		// 		customizeTheme: {
		// 			"@font-size-base": "12px",
		// 			"@border-radius-base": "2px",
		// 		},
		// 	},
		// },
		{
			plugin: ReactInspectorPlugin,
			options: {
				excludes: ["xxx-file-will-be-exclude", /regexp-to-match-file /],
			},
		}
	],
};
